package com.example.travel.activity;

import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;

import android.os.Bundle;

import androidx.appcompat.widget.Toolbar;

import com.example.travel.R;
import com.example.travel.fragment.FistContactFragment;
import com.example.travel.fragment.MineFragment;
import com.example.travel.fragment.ReacherContactFragment;
import com.example.travel.fragment.addFragment;
import com.example.travel.fragment.travel_list_fragment;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.tabs.TabLayout;

import cn.bmob.v3.Bmob;

public class MyContactActivity extends AppCompatActivity {
    DrawerLayout drawerLayout;
    Toolbar toolbar;
    NavigationView navigationView;
    ActionBarDrawerToggle toggle;//监听drawerLaout的状态变化
    TabLayout tabLayout;
    int images[]={
            R.drawable.my_info_image,R.drawable.dynamic_image,R.drawable.discovery_image
    };
    String []titles={"首页","动态","旅行攻略","组团","我的"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bmob.initialize(this, "725506ecca6f5fd13ccdb5541cddf851");
        setContentView(R.layout.activity_my_contact);
        inint();
//        toggle=new ActionBarDrawerToggle(this,
//                drawerLayout,toolbar,R.string.drawer_open,R.string.drawer_close);
//        drawerLayout.addDrawerListener(toggle);
//        setupDawer(navigationView);

        for(int i=0;i<titles.length;i++){
            tabLayout.addTab(tabLayout.newTab().setText(titles[i]));
        }
        setupTablyout(tabLayout);
        getSupportFragmentManager().beginTransaction().replace(R.id.flconent,new FistContactFragment()).commit();
    }
    public void setupTablyout(TabLayout tabLayout){
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener(){

            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                Fragment fragment=null;
                switch (tab.getPosition()){
                    case 0:
                        fragment=new FistContactFragment();
                        break;
                    case 1:
                        fragment=new addFragment();
                        break;
                    case 2:
                        fragment=new travel_list_fragment();
                        break;
                    case 3:
                        fragment=new ReacherContactFragment();
                        break;
                    case 4:
                        fragment=new MineFragment();
                        break;
                }
                getSupportFragmentManager().beginTransaction().replace(R.id.flconent,fragment).commit();

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }


//
    public void inint(){
        drawerLayout=(DrawerLayout)this.findViewById(R.id.drawer_layout);
//        toolbar=(Toolbar)this.findViewById(R.id.toolbar);
        navigationView=(NavigationView)this.findViewById(R.id.nvView);
        tabLayout=(TabLayout)this.findViewById(R.id.mytab);
    }
}
